package com.example.demo.controller;

import com.example.demo.entity.BuildingEntity;
import com.example.demo.entity.ClassroomTypeEntity;
import com.example.demo.service.BuildingService;
import com.example.demo.service.ClassroomtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.jws.WebParam;
import java.util.List;


@Controller
public class ClassroomtypeController {
    @Autowired
    private ClassroomtypeService classroomtypeService;
    @Autowired
    private BuildingService buildingService;

    @RequestMapping("selectOne")
    public String selectOne(Integer id, Model model) {
        //展示所有楼栋-----》
        List<BuildingEntity> buildingEntities = buildingService.queryBuildingAll();
        model.addAttribute("buildingList",buildingEntities);

        model.addAttribute("classroomType",classroomtypeService.queryClassroomtypeById(id));
        return "classsroom-type-update";
    }

    @RequestMapping("addClassroomType")
    public String addClassroomType(Model model){
        //展示所有楼栋-----》
        List<BuildingEntity> buildingEntities = buildingService.queryBuildingAll();
        model.addAttribute("buildingAll",buildingEntities);

        return "classsroom-type-add";
    }

    @RequestMapping("classroomType")
    public String classroomType(Model model){
        List<ClassroomTypeEntity> classroomTypeEntities = classroomtypeService.queryClassroomtypeAll();
        model.addAttribute("classroomType",classroomTypeEntities);
        System.out.println(classroomTypeEntities);
        return "classroom-type";
    }

    @RequestMapping("toaddClassroomType")
    @ResponseBody
    public int addClassroomType(ClassroomTypeEntity classroomTypeEntity){

        int i = classroomtypeService.insertClassroomtype(classroomTypeEntity);
        if (i>0){
            return 1;
        }else{
            return 0;
        }
    }
    @RequestMapping("updataClassroomType")
    @ResponseBody
    public int updataClassroomType(Model model,ClassroomTypeEntity classroomTypeEntity){

        int i = classroomtypeService.updateClassroomtype(classroomTypeEntity);
        if (i>0){
            return 1;
        }else{
            return 0;
        }
    }
    @RequestMapping("deleteClassroomType")
    @ResponseBody
    public int deleteClassroomType(Integer ctid){
        int i = classroomtypeService.deleteByIdClassroomtype(ctid);
        if (i>0){
            return 1;
        }else{
            return 0;
        }
    }


}